package com.thermofisher.dsc.amanda.customer.service.impl;

import com.thermofisher.dsc.amanda.common.crud.service.AbsBaseService;
import com.thermofisher.dsc.amanda.customer.mapper.ExclusivePriceMapper;
import com.thermofisher.dsc.amanda.customer.service.ExclusivePriceService;
import com.thermofisher.dsc.amanda.model.dto.customer.ExclusivePriceDto;
import com.thermofisher.dsc.amanda.model.po.customer.ExclusivePrice;

import com.thermofisher.dsc.amanda.tracking.service.TrackingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


import static com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type.Int;

/**
 * Created by wenjie.yang on 1/3/2019.
 */
@Service
public class ExclusivePriceServiceImpl extends
        AbsBaseService<ExclusivePriceDto, ExclusivePrice, ExclusivePriceMapper> implements ExclusivePriceService {

    /**
     * 默认构造函数
     */
    public ExclusivePriceServiceImpl(ExclusivePriceMapper mapper) {
        super(mapper);
    }

    /*@Autowired
    private UserService userService;*/
    @Autowired
    private TrackingService trackingService;

    @Override
    public ExclusivePriceDto create(ExclusivePriceDto exclusivePriceDto) {
        exclusivePriceDto.setPrice(new BigDecimal(0));
        exclusivePriceDto.setStatus(0);
        return super.create(exclusivePriceDto);
    }

    @Override
    public ExclusivePriceDto getById(Long id) {
        ExclusivePriceDto exclusivePriceDto = poToDto(mapper.selectByPrimaryKey(id));
        BigDecimal totalAmount = exclusivePriceDto.getPrice().multiply(new BigDecimal(exclusivePriceDto.getQuantity()));
        BigDecimal price=  exclusivePriceDto.getPrice();
        Integer status=exclusivePriceDto.getStatus();
        int i=price.compareTo(BigDecimal.ZERO);
        if( i==1  && status == 1){
            Map<String , Object > param = new HashMap<>();
            param.put("action","17");
            trackingService.createByAction(param);
        }
        exclusivePriceDto.setPrice(totalAmount);
        return exclusivePriceDto;
    }

}
